﻿function Play-Write{
[CmdletBinding()]
param()
	Write-Error 'first'
	Write-Error 'second'
}

function Play-WriteWithTry{
[CmdletBinding()]
param()
	try{
		Write-Error 'first'
		Write-Error 'second'
	}
	catch{
		Log-Error 'Play-WriteWithTry' $_
	}
}

function Play-Throw{
[CmdletBinding()]
param()
	throw  "first"
	throw "second"
}

function Log-Error([string]$context,[Management.Automation.ErrorRecord]$err){
	$ex=$err.Exception
	Write-Warning "Caught $($ex.GetType().Name) `"$($ex.Message)`" in $context"
}

#if will not try..catch execution of entire script will stop!
try{
	Write-Host 'Play-Write -ErrorAction Stop:'
	Play-Write -ErrorAction Stop
}
catch{
	Log-Error 'Main' $_
}

Write-Host 'Play-Write -ErrorAction Continue:'
Play-Write -ErrorAction Continue



Write-Host 'Play-WriteWithTry -ErrorAction Continue'
Write-Host 'You''ll not be in catch block inside function'
Play-WriteWithTry -ErrorAction Continue

Write-Host 'Play-WriteWithTry -ErrorAction Stop'
Write-Host 'And now will be!'
Play-WriteWithTry -ErrorAction Stop


Play-Throw
